<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      /*
        1. 新闻接口
          get http://ajax-api.itheima.net/api/news
          无参数
      */
       function myAxios(opt){
        const {method,url}=opt
        return new Promise((resolve, reject) => {
          const xhr = new XMLHttpRequest()
        // 2.设置请求的 方法 和地址
        xhr.open(method, url)
        // 3.注册回调函数 服务器响应内容回来之后触发
        xhr.addEventListener('load', function () {
          // response 响应
          // console.log(xhr.response)
          resolve(JSON.parse(xhr.response))
        })
        // 4.发送请求
        xhr.send()
        })
       }
       myAxios({
        method:'get',
        url:'http://ajax-api.itheima.net/api/settings',
       }).then(res=>{
        console.log(res);
       })

    </script>
  </body>
</html>
